<?php
final class DB {
	private $driver;
	private static $instance = NULL;
	
	public function getInstance(){
		if(self::$instance == NULL){
			self::$instance = new self;
		}
		return self::$instance;
	}
	
	private function __construct() {
		if (file_exists(LIB_PATH . DS . DB_DRIVER . '.php')) {
			require_once(LIB_PATH . DS . DB_DRIVER . '.php');
		} else {
			exit('Error: Could not load database file ' . DB_DRIVER . '!');
		}
		$driver = DB_DRIVER;
		$this->driver = new $driver(DB_HOST, DB_USER, DB_PASS, DB_NAME);
	}
		
  	public function query($sql) {
		return $this->driver->query($sql);
  	}
	
	public function escape($value) {
		return $this->driver->escape($value);
	}
	
  	public function countAffected() {
		return $this->driver->countAffected();
  	}

  	public function getLastId() {
		return $this->driver->getLastId();
  	}

	public function insertTableRow($table, $items) {
		return $this->driver->insertTableRow($table, $items);
	}

	public function updateTableRow($table, $id, $items) {
		return $this->driver->updateTableRow($table, $id, $items);
	}
}
?>